Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip config if not in interactive mode #180

Merged
merged 7 commits into from
Jun 26, 2021
Merged

Conversation

kidonng
Copy link
Contributor

@kidonng kidonng commented Jun 21, 2021

All of fzf.fish's features are only relevant and helpful in interactive mode. However, its config gets sourced even in non-interactive mode. So, let's skip configuration in non-interactive fish shells to make them a bit faster. This greatly benefits other plugins as well; for example tide makes use of non-interactive fish shells extensively.

@kidonng kidonng changed the title Skip rest of the config if not in interactive mode Skip the config if not in interactive mode Jun 21, 2021
@PatrickF1
Copy link
Owner

Great idea! I will merge this as soon as I figure out how to make it still possible to run tests locally. B/c right tests only work on CI but I run them locally when I'm developing.

@kidonng
Copy link
Contributor Author

kidonng commented Jun 21, 2021

Why not just pretend you are a CI (set -x CI true)?

Or maybe CI=true fishtape tests/**.fish

@PatrickF1
Copy link
Owner

Sure that'll work for me.

@PatrickF1
Copy link
Owner

PatrickF1 commented Jun 26, 2021

Actually, the tests still fail for me locally even with CI=true and set -x CI true
Never mind, my fault for configuring my bindings in config.fish.

@PatrickF1 PatrickF1 changed the title Skip the config if not in interactive mode Skip config if not in interactive mode Jun 26, 2021
@PatrickF1
Copy link
Owner

@kidonng can you help me answer these questions

  • I did s/subshell/session on your PR's description b/c it seems fish doesn't have subshells. Is this correct?
  • where in tide's code are non-interactive sessions run?
  • does this change affect command substitution?
  • where else are non-interactive sessions run?

@kidonng
Copy link
Contributor Author

kidonng commented Jun 26, 2021

  • I did s/subshell/session on your PR's description b/c it seems fish doesn't have subshells. Is this correct?

Subshell here is literally just shell as a subprocess. You can call it subprocess if you don't like it, but session is something entirely different.

  • where in tide's code are non-interactive sessions run?

fish_prompt. tide's code is straightforward so I guess I don't need to repeat it here.

  • does this change affect command substitution?
  • where else are non-interactive sessions run?

I'm not sure what you mean or what are you referring to, and honestly I think they are out of scope for this PR.

@PatrickF1
Copy link
Owner

I'm not sure what you mean or what are you referring to, and honestly I think they are out of scope for this PR.

I'm trying to learn these aspects of fish so I can properly write a summary of how this affects users' shell performance.

@PatrickF1
Copy link
Owner

What is fish session then?

@PatrickF1 PatrickF1 merged commit 17d54b5 into PatrickF1:main Jun 26, 2021
@PatrickF1
Copy link
Owner

PatrickF1 commented Jun 27, 2021

Ah funny that #181 was created the same day. I realized another reason this change is good: it makes fzf previews load a bit faster!

@kidonng
Copy link
Contributor Author

kidonng commented Jun 28, 2021

I'm not sure what you mean or what are you referring to, and honestly I think they are out of scope for this PR.

I'm trying to learn these aspects of fish so I can properly write a summary of how this affects users' shell performance.

🤔 Perhaps I should just give a short reply to those questions:

  • does this change affect command substitution?

That depends on what do you mean by "command substitution". But from my view, you don't usually start another fish in command substitution so no effects.

  • where else are non-interactive sessions run?

Again, are you referring to fzf.fish, tide or fish in general? I don't think I can give a better answer than reading the code/docs directly.

@kidonng
Copy link
Contributor Author

kidonng commented Jun 28, 2021

What is fish session then?

From starting a fish shell to exit this particular shell. In fact that's not a fish terminology, not even a shell terminology, it's just session's literal meaning.
There is something that I want to note, though. I consider "session" to imply an interactive launch. You don't think your shell scripts "start many sessions" right?

@kidonng
Copy link
Contributor Author

kidonng commented Jun 28, 2021

Ah funny that #181 was created the same day. I realized another reason this change is good: it makes fzf previews load a bit faster!

Hmm I don't think that issue has anything to do with this change. Glad you are happy about it though.

@PatrickF1
Copy link
Owner

Thanks for answering my questions.

Hmm I don't think that issue has anything to do with this change. Glad you are happy about it though.

It does doesn't it? When fzf loads a previews, it executes a new fish shell, which means it has to load the conf.d/fzf.fish in the process.

@kidonng
Copy link
Contributor Author

kidonng commented Jun 28, 2021

It does doesn't it? When fzf loads a previews, it executes a new fish shell, which means it has to load the conf.d/fzf.fish in the process.

That issue #181 has nothing to do with preview/shell launch speed.

The faster preview has been mentioned from the very beginning in this PR's description, until it is edited:

image

@PatrickF1
Copy link
Owner

The faster preview has been mentioned from the very beginning in this PR's description, until it is edited

😅 Oops my bad. I think I was not mentally all there when I edited it. Sorry !

PatrickF1 pushed a commit that referenced this pull request Jul 17, 2021
This fixes #183, which is a resulting bug from #180.

## Explanation of the issue

#180 makes `$_fzf_search_vars_command` unavailable for non-interactive sessions. However, `fzf_configure_bindings` depends on that variable being available. If the user puts `fzf_configure_bindings` in their `config.fish`, `fzf_configure_bindings` gets executed in non-interactive sessions e.g. fzf preview windows or by tide, and the following line in the function...

https://github.com/PatrickF1/fzf.fish/blob/17d54b576919ee77644779db2dcae56d372a8830/functions/fzf_configure_bindings.fish#L33

...essentially becomes: 

```fish
test -n $key_sequences[5] && bind --mode $mode $key_sequences[5]
```

which results in error message like `bind --preset \cv fish_clipboard_paste` or `bind: No binding found for sequence '\cv'`.

## Solution
Don't execute the entirety of `fzf_configure_bindings` if not in interactive mode. And for good measure, quote `_fzf_search_vars_command` so that even if it does get executed, the bind command will run successfully.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants